$(function () {
    obj.init();

});

var obj = new function () {
    'use strict';
    return {
        dataGrid:null,
        init:function () {
            this.dataGrid = new xhDataGrid($('#list'), 'article/getCase' , {level:3});
            this.dataGrid.parseToolbar().init().activeButton([], []);
            this.funObj().bindDataGridEvent();
            if(this.schoolId == null){ //学校id不存在
                this.dataGrid.command('showColumn','sSchoolName');
                $('#bt_list_add').hide();
            }else {
                $('#select_school').next('.combo').hide();
            }
            this.listener();
        },
        listener:function () {
            var $this = this;
            //搜索
            $('#bt_list_search').on('click' , function () {
                $this.funObj().search();
            });

            //地区
            $('#list_search_area').combobox({
                onSelect:function (rec) {
                    $this.funObj().initCity(rec);
                }
            });
        },
        funObj:function () {
            var $this = this;
            return {
                bindDataGridEvent:function () {
                    $this.dataGrid.onDblClickRow = function (rowIndex, rowData) {
                        window.top.xhTop.showModal({
                            title:'运营案例',
                            content: '<iframe src="'+baseUrl+'mobile/home/msgDetail?iArtId='+rowData['iArtId']+'"  style="width: 100%;;border-style: none;padding: 0px;height:500px"  scrolling="yes"   ></iframe>',
                            width:1000,
                            backClose:false
                        });
                    }
                },
                search:function() {
                    var key    = xhExtra.getValue($('#list_search'));
                    var area   = xhExtra.getValue($('#list_search_area'));
                    var city   = xhExtra.getValue($('#list_search_city'));
                    var level  = xhExtra.getValue($('#list_search_level'));
                    $this.dataGrid.reload({key:key,area:area,city:city , level: level});
                },
                initCity:function (rec) {
                    var pid = rec.value;
                    $('#list_search_city').combobox({
                        url:baseUrl+'school_examine/getDeps/'+pid,
                        valueField: 'id',
                        textField: 'text'
                    });
                }
            }
        }
    }
};